﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>公司数据</title>
    <link rel="stylesheet" type="text/css" href="../Content/Css/OperaMasksUI/default/om-all.css" />
    <link rel="stylesheet" type="text/css" href="../Content/Css/list.css" />
    <script type="text/javascript" src="../Scripts/jquery.1.6.3.min.js"></script>
    <script type="text/javascript" src="../Scripts/json2.js"></script>
    <script type="text/javascript" src="../Scripts/common.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/operamasks-ui.min.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/jquery.form.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/jquery.artDialog.js?skin=default"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/plugins/iframeTools.js"></script>
    <script type="text/javascript" src="../Scripts/banBackSpace.js"></script>
    <script type="text/javascript">
        var detailPanel, currentUID, mode, detailForm, validatorForm, submitForm, showDetialForm, rowData, goOn = true;
        var actionRoot = "../handler/ajax.ashx?type=AjaxSystem", comboxBankData = [], comboxTypeData = [], comboxStatusData = [];

        $(document).ready(function () {
            currentUID = art.dialog.data('currentUID');
            rowData = art.dialog.data('RowData');
            mode = art.dialog.data('Mode');
            detailForm = $('#viewForm');
            $(":input", detailForm).change(function () { detailForm.data('changed', true); });
            //编辑验证
            validatorForm = $('#viewForm').validate({
                errorContainer: "#errorMessages",
                errorLabelContainer: "#errorMessages",
                wrapper: "span",
                errorClass: "omError",
                rules: {
                    Code: { required: true },
                    Name: { required: true },
                    Type: { required: true },
                    SeqNo: { required: true }
                 },
                messages: {
                    Code: { required: "[编码]不能为空" },
                    Name: { required: "[名称]不能为空" },
                    Type: { required: "[类型]不能为空" },
                    SeqNo: { required: "[顺序号]不能为空" }
                 }
            });
            switch (mode) {
                case 'new':
                    $('#UID', detailForm).val("0");
                    $('span#button-saveadd', detailForm).omButton('enable');
                    $('#Code', detailForm).focus();
                    break;
                case 'copy':
                    $('span#button-saveadd', detailForm).omButton('disable');
                    $('#UID', detailForm).val("0");
                    $("#Code", detailForm).focus();
                    break;
                case 'update':
                    $('span#button-saveadd', detailForm).omButton('disable');
                    $("#Code", detailForm).focus();
                    break;
            }
            //显示数据
            showDetialForm("数据明细", rowData);
            $('span#button-save', detailForm).omButton({
                icons: { left: '../Content/Images/List/accept.png' }, width: 80,
                onClick: function () {
                    var sql = '';
                    if (validatorForm.form()) {
                        if (mode == 'update' && $("#UID").val() != "0") {
                            sql = " update tBaseData set "
                                + " SeqNo = " + $("#SeqNo").val()
                                + ",Code = '" + $("#Code").val() + "'"
                                + ",Name = '" + $("#Name").val() + "'"
                                + ",Type = '" + $("#Type").val() + "'"
                                + " where uid = " + $("#UID").val();
                        }
                        else {
                            sql = " INSERT INTO tBaseData( Code,	Name, [Type],	SeqNo,	UserCreateID,	CreateDate,	UserModifyID,	ModifyDate )  "
                                 + " values  ( '" + $("#Code").val() + "','" + $("#Name").val()
                                 + "','" + $("#Type").val() + "','" + $("#SeqNo").val()
                                 + "'," + currentUID + ",getdate() "
                                 + "," + currentUID + ",getdate()) ";
                        }
                    }
                    $.ajax({
                        cache: false, async: false,
                        url: '../handler/ajax.ashx?type=AjaxSystem&method=DoSql',
                        dataType: 'json', type: 'post',
                        data: { SQL: sql },
                        beforeSend: function () {
                            $.omMessageBox.waiting({
                                title: '请等待',
                                content: '系统正在提交,请稍后...'
                            });
                        },
                        complete: function () {
                            $.omMessageBox.waiting("close");
                        },
                        success: function (data) {
                            if (data.IsError) {
                                $.omMessageBox.alert({
                                    content: '错误：' + data.Message
                                });
                            }
                            else {
                                $.omMessageBox.alert({
                                    content: '保存成功。',
                                    onClose: function () {
                                        art.dialog.close();
                                    }
                                });
                            }
                        },
                        error: function (result) {
                            $.omMessageBox.waiting("close");
                        }
                    });
                }
            });
            $('span#button-cancel', detailForm).omButton({
                icons: { left: '../Content/Images/List/cross.png' }, width: 80,
                onClick: function () {
                    art.dialog.close();
                }
            });
            $('span#button-saveadd', detailForm).omButton({
                icons: { left: '../Content/Images/List/ok.gif' }, width: 80,
                onClick: function () {
                    var sql = '';
                    if (validatorForm.form()) {
                        if (mode == 'update' && $("#UID").val() != "0") {
                            sql = " update tBaseData set "
                                + " SeqNo = " + $("#SeqNo").val()
                                + ",Code = '" + $("#Code").val() + "'"
                                + ",Name = '" + $("#Name").val() + "'"
                                + ",Type = '" + $("#Type").val() + "'"
                                + " where uid = " + $("#UID").val();
                        }
                        else {
                            sql = " INSERT INTO tBaseData( Code,	Name, [Type],	SeqNo,	UserCreateID,	CreateDate,	UserModifyID,	ModifyDate )  "
                                 + " values  ( '" + $("#Code").val() + "','" + $("#Name").val()
                                 + "','" + $("#Type").val() + "','" + $("#SeqNo").val()
                                 + "'," + currentUID + ",getdate() "
                                 + "," + currentUID + ",getdate()) ";
                        }
                    }
                    $.ajax({
                        cache: false, async: false,
                        url: '../handler/ajax.ashx?type=AjaxSystem&method=DoSql',
                        dataType: 'json', type: 'post',
                        data: { SQL: sql },
                        beforeSend: function () {
                            $.omMessageBox.waiting({
                                title: '请等待',
                                content: '系统正在提交,请稍后...'
                            });
                        },
                        complete: function () {
                            $.omMessageBox.waiting("close");
                        },
                        success: function (data) {
                            if (data.IsError) {
                                $.omMessageBox.alert({
                                    content: '错误：' + data.Message
                                });
                            }
                            else {
                                content: '保存成功。',
                                $('#UID', detailForm).val("0");
                                $('#Code', detailForm).val("");
                                $('#Name', detailForm).val("");
                                $('#Code', detailForm).focus();
                            }
                        },
                        error: function (result) {
                            $.omMessageBox.waiting("close");
                        }
                    });
                }
            });
        });

        //加载数据
        showDetialForm = function (title, rowData) {
            if (detailPanel) {
                $("input[type=text]", detailPanel).val("");
                detailPanel.omPanel("open");
            }
            else {
                detailPanel = $('#detail-form').omPanel({
                    width: 'fit',
                    title: "<span style='color:#15428B;font-weight: bold;padding:6px;'>" + title + "</span>",
                    collapsed: false,
                    collapsible: false,
                    closable: false
                });
            }
            validatorForm.resetForm();
            rowData = rowData || {};
            $.each(rowData, function (n, value) {
                $("input[id='" + n + "']", detailPanel).val(value);
            })
        };
    </script>
</head>
<body>
    <div id="detail-form" style="display: none;">
        <form id="viewForm">
            <table style="width: 100%;">
                <tr>
                    <td align="left" style="display:none;" colspan="4">
                        <input type="text" class="input-text" name="UID" id="UID" /></td>
                </tr>
                <tr>
                    <td align="right" style="width: 80px; color: red;">编码</td>
                    <td align="left" style="width: 150px">
                        <input type="text" class="input-text" name="Code" id="Code" /></td>
                    <td align="right" style="width: 80px; color: red;">简称</td>
                    <td align="left" style="width: 150px">
                        <input type="text" class="input-text" name="Short" id="Short" /></td>
                </tr>
                <tr>
                    <td align="center" style="width: 80px; margin-left: 10px; color: red;">中文名称</td>
                    <td align="left" style="width: 150px">
                        <input type="text" class="input-text" name="ChnName" id="ChnName" />
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="4">
                        <span id="button-saveadd">保存新增</span>
                        <span id="button-save">保存</span>
                        <span id="button-cancel">取消</span>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</body>
</html>
